<!--
 * @description  : 物品信息登记
 * @descriptionDetail: 物品信息登记
 * @copyright    : 浙江烟草
 * @author       : mc
 * @create       : 2022-07-09 18:43:02
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999"></theme-navbar>
    <!-- #endif -->
    <view class="content main-content">
      <u-form class="form-content" :model="dataForm" ref="uForm">
        <u-form-item label="" label-position="top" v-if="param.isMust == true || param.isMust == 'true'">
          <view style="font-size: 30rpx;">
            卷烟总数共<text class="num1">
              {{ baseInfo.caseTotalQty || 0 }}
            </text>条，其中：真烟数量<text class="num2">
              {{ baseInfo.trueCigarQty || 0 }}
            </text>条，假烟数量<text class="num3">
              {{ baseInfo.falseCigarQty || 0 }}
            </text>条，走私烟数量<text class="num3">
              {{ baseInfo.smuggleQty || 0 }}
            </text>条
          </view>
        </u-form-item>
        <u-form-item label="" label-position="top">
          <show-goods-info
            :caseCode="param.caseCode"
            :isAll="isAll"
            :hasAdd="!param.justView"
            :showSearch="true"
            :caseUuid="param.caseUuid"
            :params="param"
            :height="getShowHeight()"
            ref="goodInfoRef"
            @saveRefresh="saveEvent"
            @needRefresh="needRefresh"
          ></show-goods-info>
        </u-form-item>
      </u-form>
    </view>
    <view class="submit-btns btn-other-cls">
      <u-button class="u-btn" type="primary" v-if="!param.justView" @click="saveGoodsInfo()">
        {{ isAll && !isMerged ? "合并" : "保存" }}
      </u-button>
    </view>
  </view>
</template>

<script>
import ShowGoodsInfo from "../components/showGoodsInfo.vue";
import caseService from '@/service/case/case.service.js';
export default {
  components: {
    "show-goods-info": ShowGoodsInfo,
  },
  data() {
    return {
      dataForm: {},
      param: {},
      isAll: false,
      isMerged: false,
      baseInfo: {},
    }
  },
  onLoad(pp) {
    let opt = this.getRouteParam();
    this.param.caseUuid = opt.caseUuid;
    this.param.caseCode = opt.caseCode;
    this.param.isMust = opt.isMust;
    this.param.justView = opt.justView;
  },
  computed: {

  },
  mounted() {
    this.getCountNum();
  },
  methods: {
    getCountNum() {
      if(this.param.isMust == true || this.param.isMust == 'true'){
        caseService.getCaseInfoByIdfj({
          caseUuid: this.param.caseUuid,
        }).then(res => {
          this.objMerge(this.baseInfo, res.bean);
        }).catch(res => {
          console.log(res.msg);
        });
      }
    },
    needRefresh(){
      this.getCountNum();
    },
    getShowHeight() {
      let tmp = 0;
      // #ifndef H5-DINGDING
      tmp = (this.$u.sys().windowHeight - 44 - 85 - 40 - this.$u.sys().statusBarHeight);
      // #endif
      // #ifdef H5-DINGDING
      tmp = (this.$u.sys().windowHeight - 44 - 85 - 40);
      // #endif
      return tmp;
    },
    updateBackState(param) {
      this.$refs['goodInfoRef'].updateBackState(param);
    },
    getShowAll() {
      this.isAll = !this.isAll;
      if (!this.isAll) this.isMerged = false;
      this.$refs['goodInfoRef'].refreshData(this.isAll);
    },
    saveEvent(flag) {
      if (!flag) return;
      if (this.isMerged) {
        this.isAll = false;
        this.isMerged = false;
        this.$refs['goodInfoRef'].refreshData(this.isAll);
      }
    },
    saveGoodsInfo() {
      if (this.isAll && !this.isMerged) { // 切换到所有，并且是未合并状态则进行合并
        this.$refs['goodInfoRef'].mergeData(() => {
          this.isMerged = true;
          this.$modal.alert("合并完成,是否立即保存?", "提示", () => {
            this.$refs['goodInfoRef'].saveGoods();
          }, "确定", true);
        });
      } else { // 表示保存
        this.$refs['goodInfoRef'].saveGoods();
      }
    },
  },
}
</script>

<style lang="scss" scoped>
@import "../case_common.scss";
.page{
  padding:0;
}
uni-page-body {
	height: 100%;
}

.total-tip {
	color: $u-tips-color;

	text {
		color: $u-type-warning;
		margin-left: 10rpx;
		margin-right: 10rpx;
	}
}

.flat-btn {
	position: fixed;
	bottom: 50rpx;
	margin: auto;
	left: 60rpx;
	right: 60rpx;
	z-index: 88;
}

.flat-circle {
	position: fixed;
	z-index: 999;
	right: 10rpx;
	bottom: 60rpx;
	border-radius: 50%;
	color: white;
	width: 100rpx;
	height: 100rpx;
	background-color: $u-type-warning;
	font-size: 20rpx;
	text-align: center;
	padding: 20rpx;
}

.num1 {
	font-size: 34rpx;
	color: $u-type-primary;
}

.num2 {
	font-size: 34rpx;
	color: $u-type-success;
}

.num3 {
	font-size:34rpx;
	color: $u-type-error;
}
</style>
